var app = getApp()
var status = true;
Page({
  data: {
    name: '',
    mima: '',
    status: status,
  },

  //获取输入的账号
  getName(event) {
    //console.log('账号', event.detail.value)
    this.setData({
      name: event.detail.value
    })

  },
  //获取输入的密码
  getPassword(event) {
    // console.log('密码', event.detail.value)
    this.setData({
      password: event.detail.value
    })
  },
  //点击登陆
  login() {

    let name = this.data.name
    let password = this.data.password


    console.log('账号', name, '密码', password)

    //登陆
    wx.cloud.database().collection('profiles').where({
      name: name
    }).get({
      success(res) {
        console.log("获取数据成功", res)
        let user = res.data[0]
        console.log("user", user)
        app.globalData.name = user.name
        app.globalData.dept = user.dept
        app.globalData.utime = user.shijian
        console.log('1', app.globalData.name)
        if (password == user.password) {
          console.log('登陆成功')
          wx.showToast({
              icon: 'none',
              title: '登陆成功',
            }),

            wx.reLaunch({
              url: '/pages/home/home',
            })

        } else {
          console.log('登陆失败')
          wx.showToast({
            icon: 'none',
            title: '账号或密码不正确',
          })
        }
      },
      fail(res) {
        wx.showToast({
          icon: 'none',
          title: '账号或密码不正确',
        });
        console.log("获取数据失败", res)
      }
    })
  },
  register() {
    wx.navigateTo({
      url: '../new/new',
    })
  }

})